package com.njtoyo.taxi.admin.rest.controller.business.driver;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mongo.entity.secondary.AdminDeductDriverScoreLogMongo;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.ScoreDeductingPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.ScoreDeductingCreateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.ScoreDeductingLogQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.ScoreDeductingQueryWrapper;
import com.njtoyo.taxi.admin.service.business.driver.DriverScoreDeductingService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("business/driver")
@Api(tags = {"司机管理扣分"})
public class DriverScoreDeductingController {

    @Autowired
    private DriverScoreDeductingService driverScoreDeductingService;

    @GetMapping("/score_deducting")
    @ApiOperation(value = "司机扣分列表", notes = "司机扣分列表，权限：driver_score_deducting_list")
    @PermissionScope(names = {"driver_score_deducting_list"})
    RestResult<Page<ScoreDeductingPresenter>> moneyDeducting(@ModelAttribute("admin") AdminUser adminUser, @Valid ScoreDeductingQueryWrapper wrapper) {
        return driverScoreDeductingService.getScoreDeductingList(adminUser, wrapper);
    }

    @GetMapping("/score_deducting/{id}")
    @ApiOperation(value = "司机扣分详情", notes = "司机扣分详情，权限：driver_score_deducting_detail")
    @PermissionScope(names = {"driver_score_deducting_detail"})
    RestResult<ScoreDeductingPresenter> moneyDeducting(@PathVariable("id") Long id) {
        return driverScoreDeductingService.getScoreDeducting(id);
    }

    @PostMapping("/score_deducting")
    @ApiOperation(value = "司机扣分", notes = "司机扣分，权限：driver_score_deducting")
    @PermissionScope(names = {"driver_score_deducting"})
    RestResult scoreDeducting(@ModelAttribute("admin") AdminUser adminUser, @RequestBody @Valid ScoreDeductingCreateWrapper wrapper) {
        return driverScoreDeductingService.scoreDeducting(adminUser, wrapper);
    }

    @GetMapping("/score_deducting_log")
    @ApiOperation(value = "司机扣分的管理员操作日志", notes = "司机列表，权限：driver_score_deducting_log")
    @PermissionScope(names = {"driver_score_deducting_log"})
    RestResult<PageImpl<AdminDeductDriverScoreLogMongo>> scoreDeductingLog(ScoreDeductingLogQueryWrapper wrapper) {
        return driverScoreDeductingService.scoreDeductingLog(wrapper);
    }

}
